﻿<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>添加文章</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/public/static/admin/css/oksub.css">
<!--	<script type="text/javascript" src="/public/static/admin/lib/loading/okLoading.js"></script>-->
</head>
<body>
<div class="ok-body">
	<!--form表单-->
	<form class="layui-form layui-form-pane ok-form">
		<div class="layui-form-item">
			<label class="layui-form-label">标题</label>
			<div class="layui-input-block">
				<input type="text" name="title" placeholder="请输入文章标题" autocomplete="off" class="layui-input"
				       lay-verify="required">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-block">
				<input type="checkbox" name="status" lay-skin="switch" lay-text="启用|停用" checked value="1">
				<input type="hidden" id="text1" name="text1" value="0000" >
			</div>
		</div>



		<div class="layui-form-item">

		<button type="button" class="layui-btn" id="cover">
			<i class="layui-icon">&#xe67c;</i>上轮播图
		</button>
		<img id="preview" name="preview" width="600px" height="200px">
		<input type="text" hidden="hidden"  value="" name="imagesrc" id="imagesrc1"/>
		</div>

		<!--js逻辑-->
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="addArticle">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>
<!--js逻辑-->
<script src="/public/static/admin/lib/layui/layui.js"></script>

<script>
	layui.use(["form", "okUtils", "okLayer"], function () {
		let form = layui.form;
		let okUtils = layui.okUtils;
		let okLayer = layui.okLayer;
		let okMock = layui.okMock;
		// okLoading.close();
		form.on("submit(addArticle)", function (data) {

			okUtils.ajax("often/adIm", "post", data.field, true).done(function (response) {
				okLayer.greenTickMsg(response.msg, function () {
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				});
			}).fail(function (error) {
				console.log(error)
			});
			return false;
		});
	});


	layui.use('upload', function() {
		var upload = layui.upload;
		var $ = layui.jquery;
		var uploadInst = upload.render({
			elem:'#cover'
			,url:'/admin/Often/bannerUpload'
			,accept:'file'  // 允许上传的文件类型
			,auto:true // 自动上传
			,before:function (obj) {
				console.log(obj);
				// 预览
				obj.preview(function(index,file,result) {
					// console.log(file.name);    //图片名字
					// console.log(file.type);    //图片格式
					// console.log(file.size);    //图片大小
					console.log(result);       //图片地址
					$('#preview').attr('src',result); //图片链接 base64
					$('#imagesrc1').attr('value',result);
				});
				// layer.load();
			}
			// 上传成功回调
			,done:function(res) {
				// console.log(upload);
				$('#imagesrc1').attr('value',res['url']);
				if (res.code == 0) {
					return layer.msg(res.msg);
				}
				return layer.msg(res.msg);
			}
			// 上传失败回调
			,error:function(index,upload) {
				return layer.msg(res.msg);
			}

		});
	});



</script>
</body>
</html>
